package com.mdz.sbgl.Controller;


import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mdz.sbgl.Entity.Glyb;
import com.mdz.sbgl.Entity.Sbuser;
import com.mdz.sbgl.Mapper.GlybMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 孟德志
 * @since 2021-01-25
 */
@Controller
@RequestMapping("/sbgl/glyb")
public class GlybController {

    @Autowired
    private GlybMapper glybMapper;
    @Autowired
    private HttpSession session;

    @ResponseBody
    @GetMapping(value = "/login/{loginName}/{loginPassword}")
    public List<Glyb> login(@PathVariable("loginName") String loginName, @PathVariable("loginPassword") String loginPassword) {
        String Password = SecureUtil.md5(loginPassword);
        List<Glyb> user = glybMapper.selectList(new QueryWrapper<Glyb>().eq("login_name", loginName).eq("login_password", Password));
        session.setAttribute("username", user.get(0).getUserName());
        session.setAttribute("loginname", user.get(0).getLoginName());
        session.setAttribute("userid", user.get(0).getId());
        return user;
    }

}

